// 분류별 필터 class CategorySearchFilter { constructor(option) { this.items = []; this.option = option; const keyword_items = document.querySelectorAll("input[name^='category_filter_item[']"); keyword_items.forEach((element) => { if (element.checked) { this.setItem(element, element.checked); this.filterCloneGenerator(); } }); } setSearchProductCount(search_product_count) { if (document.querySelector('.filter-wrap .total-count')) { document.querySelector('.filter-wrap .total-count').innerHTML = search_product_count + "개 상품"; } } event() { const keyword_items = document.querySelectorAll("input[name^='category_filter_item[']"); keyword_items.forEach((element) => { element.addEventListener('click', (e) => this.itemHandler(e.target, e.target.checked)); }); if (document.querySelector('.filter-wrap .select-filter')) { document.querySelector('.filter-wrap .select-filter').addEventListener('click', (e) => this.cloneHandler(e.target)); } if (document.querySelector('.filter-wrap .btn-reset')) { document.querySelector('.filter-wrap .btn-reset').addEventListener('click', () => { this.items = []; keyword_items.forEach((element) => { element.checked = false; }); this.filterCloneGenerator(); if (this.option.auto_submit) { this.getProduct(); } }); } if (document.querySelector('.filter-wrap .btn-search')) { document.querySelector('.filter-wrap .btn-search').addEventListener('click', () => { this.getProduct(); }); } } cloneHandler(element) { if (element.dataset.filter_id && element.dataset.keyword_id) { const { filter_id, keyword_id } = element.dataset; this.itemHandler(element, false); if (document.querySelector(`input[name='category_filter_item[${filter_id}]'][value='${keyword_id}']`)) { document.querySelector(`input[name='category_filter_item[${filter_id}]'][value='${keyword_id}']`).checked = false; } } } itemHandler(element, checked) { this.setItem(element, checked); this.filterCloneGenerator(); if (this.option.auto_submit) { this.getProduct(); } } filterCloneGenerator() { if (document.querySelector('.filter-wrap .select-filter')) { const html = []; this.items.forEach((item) => { let option_type = (item.option_type && typeof this[item.option_type] === 'function') ? item.option_type : 'keyword'; if (!this.option.display_color) { option_type = 'keyword'; } html.push(`